package com.yvon.boot.mybatis.support;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.Query;
import com.baomidou.mybatisplus.core.metadata.TableFieldInfo;
import com.baomidou.mybatisplus.core.toolkit.ExceptionUtils;
import com.baomidou.mybatisplus.core.toolkit.support.SFunction;
import com.baomidou.mybatisplus.extension.conditions.AbstractChainWrapper;
import com.yvon.boot.mybatis.IBaseService;

import java.util.function.Predicate;

/**
 * @author admin
 */
public class LambdaDeleteWrapperChain<T> extends AbstractChainWrapper<T, SFunction<T, ?>, LambdaDeleteWrapperChain<T>, LambdaQueryWrapper<T>> implements Query<LambdaDeleteWrapperChain<T>, T, SFunction<T, ?>> {
    private IBaseService<T> baseService;

    public LambdaDeleteWrapperChain(IBaseService<T> baseService) {
        this.baseService = baseService;
        super.wrapperChildren = new LambdaQueryWrapper();
    }

    @Override
    @SafeVarargs
    public final LambdaDeleteWrapperChain<T> select(SFunction<T, ?>... columns) {
        ((LambdaQueryWrapper)this.wrapperChildren).select(columns);
        return (LambdaDeleteWrapperChain)this.typedThis;
    }

    @Override
    public LambdaDeleteWrapperChain<T> select(Predicate<TableFieldInfo> predicate) {
        ((LambdaQueryWrapper)this.wrapperChildren).select(predicate);
        return (LambdaDeleteWrapperChain)this.typedThis;
    }

    @Override
    public LambdaDeleteWrapperChain<T> select(Class<T> entityClass, Predicate<TableFieldInfo> predicate) {
        ((LambdaQueryWrapper)this.wrapperChildren).select(entityClass, predicate);
        return (LambdaDeleteWrapperChain)this.typedThis;
    }

    @Override
    public String getSqlSelect() {
        throw ExceptionUtils.mpe("can not use this method for \"%s\"", new Object[]{"getSqlSelect"});
    }

    public boolean execute() {
        return this.baseService.remove(this.getWrapper());
    }
}